/*
 * ListenerManager.h
 *
 *  Created on: 2012-8-27
 *      Author: yangentao@gmail.com
 */

#ifndef LISTENERMANAGER_H_
#define LISTENERMANAGER_H_

#include "Vector.h"

template<typename T>
class ListenerManager {
private:
	Vector<T*> listeners;

	Vector<T*> back;
	int current;
public:
	ListenerManager(): current(0){
	}
	virtual ~ListenerManager(){
		listeners.clear();
		back.clear();
	}
public:
public:
	void addListener(T* listener) {
		if (!listeners.contains(listener)) {
			listeners.append(listener);
		}
	}
	void removeListener(T* listener) {
		listeners.removeValue(listener);
	}
	void clearListeners(){
		listeners.clear();
	}
public:
	void startIterate(){
		back = listeners;
		current = 0;
	}
	T* next(){
		if(current >=0 && current < back.size()){
			return back.get(current++);
		}
		return 0;
	}
};

#endif /* LISTENERMANAGER_H_ */
